<?php


namespace App\Admin\Handers;

use App\Models\Room;
use App\Models\Store;
use App\Models\StoreDetail;
use EasyWeChat\Factory;
use Illuminate\Support\Facades\Storage;

class WeChatHander
{
	
	// 获取门店房间二维码
	public function getStoreRoomQrCode($store_id = 0, $room_id = 0)
	{
		$scene = [
			'store_id' => $store_id,
			'room_id' => $room_id,
		];
		
		$scene = json_encode($scene);
		
		$page = 'pages/index/index';
		$url = "http://dev-ktvnewproapi.ffun360.com/wechat/small_program_code".
			"?json=pages/index/index?data=".$scene;
		
		$res = $this->httpGet($url);
		if(!empty($res)) {
			$room = Room::where('store_id', $store_id)
				->where('id', $room_id)
				->first();
			
			$room->room_qrcode_img = $res;
			$room->save();
		}
	}

	public function httpGet($url)
    {
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($curl, CURLOPT_TIMEOUT, 500);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
        curl_setopt($curl, CURLOPT_URL, $url);
        $res = curl_exec($curl);
        curl_close($curl);
        return $res;
    }
}